package ph.gov.marikina.mcsmtms.services.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import ph.gov.marikina.mcsmtms.dao.SettingsDAO;
import ph.gov.marikina.mcsmtms.domain.Settings;
import ph.gov.marikina.mcsmtms.services.SettingsService;

public class SettingsServiceImpl implements SettingsService {

	private SettingsDAO settingsDAO;

	public SettingsDAO getSettingsDAO() {
		return settingsDAO;
	}

	public void setSettingsDAO(SettingsDAO settingsDAO) {
		this.settingsDAO = settingsDAO;
	}
	
	@Override
	public Settings getDefaultSettings() {
		return settingsDAO.getSettings(1);
	}
	
	@Override
	public Date getDefaultSystemDate() {
		Calendar systemCalendar = new GregorianCalendar();
		systemCalendar.setTime(getDefaultSettings().getSystemDate());;
		Calendar currentCalendar = new GregorianCalendar();
		currentCalendar.setTime(new Date());
		currentCalendar.set(Calendar.YEAR, systemCalendar.get(Calendar.YEAR));
		currentCalendar.set(Calendar.MONTH, systemCalendar.get(Calendar.MONTH));
		currentCalendar.set(Calendar.DATE, systemCalendar.get(Calendar.DATE));

		return currentCalendar.getTime();
	}
}
